/*
 * @Description:
 * @Author: py
 * @Date: 2025-03-04
 */
import { store } from '@fl/store/index'
import { defineStore } from 'pinia'

type StatementInfo = {
    actualInvoiceAmount?: number
    actualSettlementAmount?: number
    commission?: number
    createTime?: string
    vendorConfirm?: string | null
    vendorConfirmUrl?: string | null
    differenceReason?: string
    dueSettlementAmount?: number
    dueInvoiceAmount?: number
    exceptionAmount?: number
    exceptionSettlementUrl?: string
    exceptionTime?: string
    exceptionType: number
    id?: string
    invoiceDiff: number
    invoiceNumber?: string
    invoiceTime?: string
    invoiceUrl?: string
    operatorId?: string
    operatorName?: string
    parkingFee?: number
    platformServiceFee?: number
    reconciliationCode?: string
    reconciliationDate?: string
    reconciliationEndDate?: string
    reconciliationName?: string
    reconciliationStartDate?: string
    reconciliationStatus: number
    reconciliationTime?: number
    revenue?: number
    settlementCount?: number
    settlementDiff: number
    solutionSuggestion?: string
    totalAmount?: number
    updateTime?: string
    vendorId?: string
    vendorName?: string
    [key: string]: any
}

type StatementState = {
    statementInfo: StatementInfo
    statementUpdateMoment: number | null
}

export const useChargeSettleStore = defineStore('chargeSettle', {
    actions: {
        setStatementInfo(oInfo: StatementInfo) {
            this.statementInfo = oInfo
        },
        updateStatementRecord() {
            this.statementUpdateMoment = Date.now()
        },
    },
    getters: {
        getStatementInfo(state): StatementInfo {
            return state.statementInfo
        },
        getStatementUpdateMoment(state) {
            return state.statementUpdateMoment
        },
    },
    persist: true,
    state: (): StatementState => ({
        statementInfo: {
            exceptionType: 0,
            invoiceDiff: 0,
            reconciliationStatus: 0,
            settlementDiff: 0,
        }, // 对账单详情
        statementUpdateMoment: null,
    }),
})

export function useChargeSettleStoreWithOut() {
    return useChargeSettleStore(store)
}
